layui.use(['table', 'laytpl', 'layer'], function() {
	var url = location.href;
	var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
	var id = paraString[0].substring(paraString[0].indexOf("=") + 1, paraString[0].length);
	var type = paraString[1].substring(paraString[1].indexOf("=") + 1, paraString[1].length);
	var $ = layui.$;
	if(type == 'edit') {
		customerMsg();
		noreadonly();
	} else {
		readonly();
		customerMsg();
	}

	function customerMsg() {
		$.ajax({
			type: "post",
			url: "/customermsg",
			async: true,
			data: {
				id: id
			},
			success: function(data) {
				var ret = JSON.parse(data);
				$(".username").val(ret.username);
				$(".email").val(ret.email);
				$(".phone").val(ret.phone);
			}
		});
	}

	function readonly() {
		$(".username").attr("readonly", "readonly");
		$(".email").attr("readonly", "readonly");
		$(".phone").attr("readonly", "readonly");
	}

	function noreadonly() {
		$(".username").removeAttr("readonly");
		$(".email").removeAttr("readonly");
		$(".phone").removeAttr("readonly");
	}
});